package com.pda.gongpin.ui.shipments;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.pda.gongpin.R;
import com.pda.gongpin.adapter.ShipmentsAdapter;
import com.pda.gongpin.bean.ShipmentsDetailsBean;
import com.pda.gongpin.bean.request.DeliveryNoRequest;
import com.pda.gongpin.contract.ShipmentsContract;
import com.pda.gongpin.dialog.AffirmDialog;
import com.pda.gongpin.presenter.ShipmentsPresenter;
import com.wangshen.base.app.AppActivityKey;
import com.wangshen.base.ui.mvp.base.ui.BaseMvpActivity;
import com.wangshen.base.ui.mvp.base.ui.BaseMvpFragment;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class ShipmentsFragment extends BaseMvpFragment<ShipmentsPresenter> implements ShipmentsContract.View {

    @BindView(R.id.tv_deliveryNo)
    TextView tvDeliveryNo;
    @BindView(R.id.tv_ownerCode)
    TextView tvOwnerCode;
    @BindView(R.id.tv_partner)
    TextView tvPartner;
    @BindView(R.id.tv_recipient)
    TextView tvRecipient;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.tv_shipmentsManner)
    TextView tvShipmentsManner;
    @BindView(R.id.tv_logisticsCompanies)
    TextView tvLogisticsCompanies;
    @BindView(R.id.rv_list)
    RecyclerView rvList;
    @BindView(R.id.tv_move_out)
    TextView tvMoveOut;
    private String deliveryNo,state,originOrderNum;
    ShipmentsAdapter shipmentsAdapter;

    @Override
    public ShipmentsPresenter getPresenter() {
        return new ShipmentsPresenter();
    }

    public ShipmentsFragment(String deliveryNo,String state,String originOrderNum) {
        this.deliveryNo = deliveryNo;
        this.state=state;
        this.originOrderNum=originOrderNum;
    }

    public ShipmentsFragment() {
    }

    @Override
    public int getViewId() {
        return R.layout.activity_shipments;
    }

    @Override
    public void initView() {
        shipmentsAdapter=new ShipmentsAdapter(R.layout.item_shipment_detail,new ArrayList<>());
        rvList.setAdapter(shipmentsAdapter);
        presenter.shipmentsManifest(new DeliveryNoRequest(deliveryNo));
        if (state.equals("已发货")){
            tvMoveOut.setVisibility(View.GONE);
        }else {
            tvMoveOut.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void initLinsenterner() {

    }

    @Override
    public void getData() {

    }

    @Override
    public void setData(ShipmentsDetailsBean bean) {
        tvAddress.setText(bean.getDeliveryResult().getAddress());
        tvDeliveryNo.setText(bean.getDeliveryResult().getDeliveryNo());
        tvLogisticsCompanies.setText(bean.getDeliveryResult().getLogisticsCompanies());
        tvOwnerCode.setText(bean.getDeliveryResult().getOwnerCodeName());
        tvPartner.setText(bean.getDeliveryResult().getPartner());
        tvShipmentsManner.setText(bean.getDeliveryResult().getShipmentsManner());
        tvRecipient.setText(bean.getDeliveryResult().getRecipient());
        shipmentsAdapter.setNewInstance(bean.getSkuDeliveryScheduleResult());
    }


    @OnClick({ R.id.tv_move_out})
    public void onViewClicked(View view) {
        switch (view.getId()) {

            case R.id.tv_move_out:
                AffirmDialog affirmDialog=new AffirmDialog(mContext, new AffirmDialog.OnConfrim() {
                    @Override
                    public void onConfrim() {
                        DeliveryNoRequest request=new DeliveryNoRequest(deliveryNo);
                        presenter.shipments(request);
                    }
                });
                affirmDialog.show("确认要开始发货吗？");
                break;
        }
    }
}
